<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script src = "protobufjs.js"></script>
<script>
let m = protobuf.Root.fromJSON({
  "nested": {
    "Request": {
      "fields": {
        "Headers": {
          "rule": "repeated",
          "type": "Headers",
          "id": 5
        },
        "ContentEncoding": {
          "type": "string",
          "id": 6
        },
        "ContentType": {
          "type": "string",
          "id": 7
        },
        "Payload": {
          "type": "bytes",
          "id": 8
        }
      }
    },
    "Headers": {
      "fields": {
        "Key": {
          "type": "string",
          "id": 1
        },
        "Value": {
          "type": "string",
          "id": 2
        }
      }
    }
  }
});
let WS_Request = m.lookupType("Request");
// 序列化 encode
let data = {
    Headers:[
        {
            Key:'qq',
            Value:'11111'

        },{
         Key:'vx',
            Value:'2222'
        }
    ],
    ContentEncoding:'utf-8',
    ContentType:'text',
    Payload:new Uint8Array([1,1,1,1])

}


let encode_data = WS_Request.encode(data).finish()
console.log(encode_data)



// 反序列化 decode
let decode_data = WS_Request.decode(encode_data)
console.log(decode_data)





</script>

</body>
</html>